package util

import (
	"reflect"
)

//翻译php函数  低阶版本，只取出单个key重组成list（切片）
func ArrayColumn(array interface{}, key string) (list []interface{}) {
	valueOf := reflect.ValueOf(array)
	for i := 0; i < valueOf.Len(); i++ {
		one := valueOf.Index(i)
		one = one.Elem() //指针不能操作
		value := one.FieldByName(key)
		kind := value.Kind()
		switch kind {
		case reflect.Int:
			list = append(list, value.Int())
		case reflect.String:
			list = append(list, value.String())
		default:
			list = append(list, value)
		}
	}
	return list
}
